export class IndexService {
  constructor() { }

  getFormContent(list, constObj) {
    let content = list.map(item => {
      let formatData = {};
      // 表单生成类型
      formatData.type = constObj[item.attributeType];
      formatData['el'] = {};
      formatData['el']['clearable'] = true;
      formatData['el']['placeholder'] = item.attributeType === 1 || item.attributeType === 5 ? '请输入' : '请选择';
      if (item.attributeType === 6) {
        formatData['el']['type'] = 'datetime';
        formatData['el']['valueFormat'] = 'yyyy-MM-dd HH:mm:ss';
      } else if (item.attributeType === 4) {
        formatData['el']['valueFormat'] = 'yyyy-MM-dd';
      }
      formatData.id = item.attributeNameValue;
      formatData.label = item.attributeName;
      formatData.options = item.valueRange ? JSON.parse(item.valueRange) : [];
      formatData.rules = [];
      if (item.isMust) {
        formatData.rules.push({ required: true, message: '此项必填', trigger: 'change' });
      }
      if (item.attributeType === 5) {
        formatData.rules.push({ pattern: /^\d*$/, message: '请输入数字', trigger: 'blur' });
      }
      if (item.attributeType === 1 || item.attributeType === 5) {
        formatData.rules.push({ max: 50, message: '最长50个字符', trigger: 'blur' });
      }
      return formatData;
    });
    return content || [];
  }
}
